package com.dncompute.marrow;

import java.io.IOException;
import java.util.ArrayList;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class Controller {
	
	public HttpServletRequest req;
	public HttpServletResponse res;
	
	
	/**
	 * 
	 * Should usually return false.
	 * Return true only in cases where you've handled the response entirely in this method
	 * and don't wish the dispatcher to pass the request further on
	 * 
	 * Examples of when you would return true:
	 * -Service requires authentication and user is not authenticated. Failure to authenticate 
	 * could be handled in the preprocess method
	 * 
	 * 
	 * @param path
	 * @return whether or not this method consumed the request
	 */
	protected boolean preprocess(ArrayList<String> path) {
		return false;
	}
	
	
	/**
	 * 
	 * Utility method for forwarding requests
	 * 
	 * @param viewPath
	 * @throws ServletException
	 * @throws IOException
	 */
	protected void forward(String viewPath) throws ServletException, IOException  {
		RequestDispatcher view = req.getRequestDispatcher(viewPath);
		view.forward(req, res);
	}


	
}
